<template>
	<view class="">
		{{code || null}}
	</view>
</template>

<script>
	import { SetWxopenid } from '@/api/Users.js'
	import wx from 'weixin-js-sdk'
	export default {
		name: "login",
		data() {
			return {
				code: '',
				token:''
			};

		},
		onLoad({ code, state,token }) {
			this.code = code;
			this.token=token;
			this.init();
		},
		methods: {
			async init() {
				this.SetWxopenid()
				// if (!this.code) {
				// 	this.getBaseInfos();
				// } else {
				// 	const { success, msg } = await SetWxopenid({
				// 		code: this.code
				// 	})
				// 	this.Toast(msg)
				// }
			},
			// getBaseInfos() {
			// 	var url_code =
			// 		"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx2effae1f8bdc8283&redirect_uri=https://app.ciligf.com/#/pages/Wechat&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect";
			// 	window.location.href = url_code; //打开这个链接，你的url后面就会跟上code的参数

			// },
			async SetWxopenid() {
				let res = await SetWxopenid({
					token:this.token,
					code: this.code // this.$route.query.code
				})
				console.log('res===>',res)
				//跳转回小程序的登录页面并将公众号openid带过去
				wx.miniProgram.redirectTo({ url: "/pages/auth/login/login?mpOpenid=" + res.data.data })


				// getMpUserInfo(this.$route.query.code).then(res => {
				// 	//跳转回小程序的登录页面并将公众号openid带过去
				// 	wx.miniProgram.redirectTo({ url: "/pages/auth/login/login?mpOpenid=" + res.data.data })
				// })
			}
		},

	}
</script>

<style lang="scss">

</style>